<template>
  <div class="educationadd">
    <div class="home">
      <div class="navheaders">
        <van-nav-bar @click-left="back">
          <template #left>
            <van-icon name="arrow-left" color="#fff" size="0.6rem" />
          </template>
          <template #title>
            <span>
              <img src="../../assets/img/logo.png" />
            </span>
          </template>
          <!-- <template #right>
            <van-icon name="wap-nav" color="#fff" size="0.6rem" />
          </template>-->
        </van-nav-bar>
      </div>
    </div>

    <div class="myumeremove">
      <div class="educationaddchild">
        <!-- <div class="educationaddchildcont">
          <p class="educationaddlift">失业人员统计添加</p>
        </div> -->
        <van-divider color="#E8E8E8" />
        <van-form @submit="onSubmit" label-align="right">
          <p class="enplouheader">已就业人数</p>
          <van-field v-model="formdata.rejrs3" name="rejrs3" :maxlength="6" @input="clickje" label="单位就业" type="digit"
            placeholder="请输入单位就业人数" :rules="[{ required: true, message: ' ' },
           ]" />
          <van-field v-model="formdata.rejrs4" :maxlength="6" name="rejrs4" @input="clickje" label="灵活就业" type="digit"
            placeholder="请输入灵活就业人数" :rules="[{ required: true, message: ' ' },
           ]" />
          <!-- <van-field v-model="formdata.rejrs2" name="rejrs2" label="已就业人数小计" type="digit" readonly :rules="[{ required: true, message: ' ' },
           ]" /> -->
          <p class="enplouheader">未就业人数</p>
          <van-field v-model="formdata.rejrs6" name="rejrs6" :maxlength="6" @input="clickyyy" label="有就业意愿" type="digit"
            placeholder="请输入有就业意愿人数" :rules="[{ required: true, message: ' ' },
           ]" />
          <p class="enplouheader">无就业意愿人数</p>
          <van-field v-model="formdata.rejrs8" name="rejrs8" :maxlength="6" @input="clickwyu" label="照顾家人" type="digit"
            placeholder="请输入照顾家人人数" :rules="[{ required: true, message: ' ' },
           ]" />
          <van-field v-model="formdata.rejrs9" name="rejrs9" :maxlength="6" @input="clickwyu" label="身体原因" type="digit"
            placeholder="请输入身体原因人数" :rules="[{ required: true, message: ' ' },
           ]" />
          <van-field v-model="formdata.rejrs10" name="rejrs10" :maxlength="6" @input="clickwyu" label="升学，备考"
            type="digit" placeholder="请输入升学，备考人数" :rules="[{ required: true, message: ' ' },
           ]" />
          <van-field v-model="formdata.rejrs11" name="rejrs11" :maxlength="6" @input="clickwyu" label="主观意愿不强"
            type="digit" placeholder="请输入主观意愿不强人数" :rules="[{ required: true, message: ' ' },
           ]" />
          <van-field v-model="formdata.rejrs12" name="rejrs12" :maxlength="6" @input="clickwyu" label="其他" type="digit"
            placeholder="请输入其他人数" :rules="[{ required: true, message: ' ' },
           ]" />
          <!-- <van-field v-model="formdata.rejrs7" name="rejrs7" label="无就业意愿小计" type="digit" readonly :rules="[{ required: true, message: ' ' },
           ]" />
          <van-field v-model="formdata.rejrs5" name="rejrs5" label="未就业人数总计" type="digit" readonly :rules="[{ required: true, message: ' ' },
           ]" />
          <van-field v-model="formdata.rejrs1" name="rejrs1" label="辖区内劳动力总人数" type="digit" readonly :rules="[{ required: true, message: ' ' },
           ]" /> -->
          <div style="margin: 16px;">
            <van-button round block type="info" style="width:8rem" native-type="submit">
              保存
            </van-button>
          </div>
        </van-form>

      </div>
    </div>
  </div>
</template>
<script>
import UNEMPLOY from '@/api/unemploy'
export default {

  data () {
    return {

      formdata: {
        rejrs1: '',//辖区内劳动力总人数
        rejrs2: '',//已就业人数小计
        rejrs3: '',//单位就业
        rejrs4: '',//灵活就业
        rejrs5: '',//未就业人数小计
        rejrs6: '',//有就业意愿人数
        rejrs7: '',//未就业人数小计
        rejrs8: '',//照顾家人
        rejrs9: '',//身体原因
        rejrs10: '',//升学备考
        rejrs11: '',//主观意愿不强
        rejrs12: '',//其他
        id: ""
      }
    }
  },
  computed: {},
  methods: {
    //已就业人数小计
    clickje () {
      this.formdata.rejrs2 = Number(this.formdata.rejrs3) + Number(this.formdata.rejrs4)
      this.formdata.rejrs1 = Number(this.formdata.rejrs2) + Number(this.formdata.rejrs5)
    },
    //有就业意愿
    clickyyy () {

      this.formdata.rejrs5 = Number(this.formdata.rejrs6) + Number(this.formdata.rejrs7)
      this.formdata.rejrs1 = Number(this.formdata.rejrs2) + Number(this.formdata.rejrs5)
    },
    //无就业意愿
    clickwyu () {
      this.formdata.rejrs7 = Number(this.formdata.rejrs8) + Number(this.formdata.rejrs9) + Number(this.formdata.rejrs10) + Number(this.formdata.rejrs11) + Number(this.formdata.rejrs12)
      this.formdata.rejrs5 = Number(this.formdata.rejrs6) + Number(this.formdata.rejrs7)
      this.formdata.rejrs1 = Number(this.formdata.rejrs2) + Number(this.formdata.rejrs5)
    },




    back () {

      this.$router.go(-1)

    },


    // 工作经历新增修改
    onSubmit () {
      let params = this.formdata
      if (this.formdata.id === "") {
        let now = new Date();
        let year = now.getFullYear(); //得到年份
        let month = now.getMonth();//得到月份
        let date = now.getDate();//得到日期
        let hour = now.getHours();//得到小时
        let minu = now.getMinutes();//得到分钟
        let sec = now.getSeconds();//得到秒
        month = month + 1;
        if (month < 10) month = "0" + month;
        if (date < 10) date = "0" + date;
        if (hour < 10) hour = "0" + hour;
        if (minu < 10) minu = "0" + minu;
        if (sec < 10) sec = "0" + sec;
        let timedata = year + "-" + month + "-" + date + " " + hour + ":" + minu + ":" + sec
        params.createTime = timedata
        UNEMPLOY.employmentInsert(params).then(res => {
          this.buttondisabled = false
          console.log(res.data)
          if (res.data.success) {
            this.$toast('添加成功')
            this.$router.push({
              name: 'unemploy',
              query: {
                num: 2
              }
            })
          } else {
            this.$notify(res.data.msg)
          }
        })
      } else {
        UNEMPLOY.employmentUpdate(params).then(res => {
          this.buttondisabled = false
          console.log(res.data)
          if (res.data.success) {
            this.$toast('修改成功')
            this.$router.push({
              name: 'unemploy',
              query: {
                num: 2
              }
            })
          } else {
            this.$notify(res.data.msg)
          }
        })
      }

    },

    getDetail () {
      UNEMPLOY.employmentGetid(this.$route.query.id).then(res => {
        if (res.data.success) {
          this.formdata = res.data.data || {};
        } else {
          this.$message.error(`${data.msg}`);
        }
      });
    },
  },
  created () {

    if (this.$route.query.id) {
      this.getDetail()
    }
  }
}
</script>
<style scoped>
.myumeremove .educationaddchild /deep/ .van-cell__title {
  font-weight: 400;
  text-align: right;
  margin: 0.24rem 0;
  width: 4rem;
}
.enplouheader {
  font-weight: bold;
}
.myumeremove .educationaddchild /deep/ .van-field__control {
  padding-right: 0;
}
</style>
